export const WindowUtil = {
  /**
   * 浏览器判断是否全屏
   */
  fullscreenToggel() {
    if (this.fullscreenEnable()) {
      this.exitFullScreen();
    } else {
      this.reqFullScreen();
    }
  },

  /**
   * esc监听全屏
   */
  listenfullscreen(callback) {
    function listen() {
      callback();
    }
    document.addEventListener('fullscreenchange', function () {
      listen();
    });
    document.addEventListener('mozfullscreenchange', function () {
      listen();
    });
    document.addEventListener('webkitfullscreenchange', function () {
      listen();
    });
    document.addEventListener('msfullscreenchange', function () {
      listen();
    });
  },

  /**
   * 浏览器判断是否全屏
   */
  fullscreenEnable() {
    return document.isFullScreen || document.mozIsFullScreen || document.webkitIsFullScreen;
  },

  /**
   * 浏览器全屏
   */
  reqFullScreen() {
    if (document.documentElement.requestFullScreen) {
      document.documentElement.requestFullScreen();
    } else if (document.documentElement.webkitRequestFullScreen) {
      document.documentElement.webkitRequestFullScreen();
    } else if (document.documentElement.mozRequestFullScreen) {
      document.documentElement.mozRequestFullScreen();
    }
  },

  /**
   * 浏览器退出全屏
   */
  exitFullScreen() {
    if (document.documentElement.requestFullScreen) {
      document.exitFullScreen();
    } else if (document.documentElement.webkitRequestFullScreen) {
      document.webkitCancelFullScreen();
    } else if (document.documentElement.mozRequestFullScreen) {
      document.mozCancelFullScreen();
    }
  },

  /**
   * 判断浏览器是否最小化
   * @returns {boolean}
   */
  isMinStatus() {
    let isMin = false;
    if (window.outerWidth) {
      isMin = window.outerWidth <= 160 && window.outerHeight <= 30;
    } else {
      isMin = window.screenTop < -30000 && window.screenLeft < -30000;
    }
    return isMin;
  },
};
